{% extends 'layout/manage.html' %}

{% block css %}
    <style>
        .project {
            margin-top: 10px;
        }

        .panel-body {
            padding: 0;
            display: flex;
            flex-direction: row;
            justify-content: left;
            align-items: flex-start;
            flex-wrap: wrap;
        }

        .panel-body > .item {
            border-radius: 6px;
            width: 228px;
            border: 1px solid #dddddd;
            margin: 20px 10px;

        }

        .panel-body > .item:hover {
            border: 1px solid #f0ad4e;
        }

        .panel-body > .item > .title {
            height: 104px;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            border-top-left-radius: 6px;
            border-top-right-radius: 6px;
            font-size: 15px;
            text-decoration: none;
        }

        .panel-body > .item > .info {
            padding: 10px 10px;
            {#margin-left: 10px;#}
            {#margin-right: 10px;#}
            display: flex;
            justify-content: space-between;

            border-bottom-left-radius: 3px;
            border-bottom-right-radius: 3px;
            color: #8c8c8c;

        }

        .panel-body > .item > .info a {
            text-decoration: none;
        }

        .panel-body > .item > .info .fa-star {
            font-size: 20px;
        }

        .panel-body > .item > .ctime {
            margin-left: 10px;
            padding-right: 10px;
        {#float: right;#}{#display: flex;#}{##}{#justify-content: space-between;#}{#border-bottom-left-radius: 6px;#}{#border-bottom-right-radius: 6px;#} color: #8c8c8c;
        }

        .panel-body > .item > .ctime span {
            font-size: 10px;

        }

        .color-radio label {
            margin-left: 0;
            padding-left: 0;
        }

        .color-radio input[type='radio'] {
            display: none;
        }

        .color-radio input[type='radio'] + .cycle {
            display: inline-block;
            height: 25px;
            width: 25px;
            border-radius: 50%;
            border: 2px solid #dddddd;
        }

        .color-radio input[type='radio']:checked + .cycle {
            border: 2px solid black;
        }

    </style>
{% endblock %}

{% block content %}
    <!-- 创建项目按钮 -->
    <div class="container-fluid project" style="margin: 10px 0;">
        <a class="btn btn-primary" data-toggle="modal" data-target="#myModal" >
            <i class="fa fa-plus-circle" aria-hidden="true"></i> 新建项目
        </a>
    </div>
    <!-- modal模态框  创建项目表单 -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">新建项目</h4>
                </div>
                <div class="modal-body">
                    <form id="addForm">
                        {% csrf_token %}
                        {% for field in form %}
                            <div class="form-group">
                                <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                                {{ field }}
                                <span class="error-msg"></span>
                            </div>
                        {% endfor %}
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button id="btnSubmit" type="button" class="btn btn-primary">创建</button>
                </div>
            </div>
        </div>
    </div>
    <!-- 面板：项目列表：星标，我创建的，我参与的 -->
    <div class="panel panel-default">
        <div class="panel-heading"><i class="fa fa-star" aria-hidden="true"></i> 星标项目</div>
        <div class="panel-body">
            {#显示项目#}
            {% for item in project_dict.star %}
                <div class="item">
                    {#项目盒子 颜色展示 项目名称显示#}
                    <a href="{% url 'dashboard' project_id=item.value.id %}" class="title" style="background-color: {{ item.value.get_color_display }}">{{ item.value.name }}</a>
                    {# 项目盒子底部 #}
                    <div class="info">
                        <div>
                            {# 项目星标 #}
                            <a href="{% url 'project_unstar' project_type=item.type project_id=item.value.id %}">
                                <i class="fa fa-star" aria-hidden="true" style="color: #f0ad4e"></i>
                            </a>
                            {# 项目创建者 #}
                            <span>{{ item.value.creator.username }}</span>
                        </div>
                        <div>
                            {# 参与人数 #}
                            <i class="fa fa-user-o" aria-hidden="true"></i>
                            <span>{{ item.value.join_count }}</span>
                        </div>
                    </div>

                </div>
            {% endfor %}
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading"><i class="fa fa-list" aria-hidden="true"></i> 我创建的项目</div>
        <div class="panel-body">
            {#显示项目#}
            {% for item in project_dict.my %}
                {# 项目盒子 #}
                <div class="item">
                    {#项目盒子 颜色展示 项目名称显示#}
                    <a href="{% url 'dashboard' project_id=item.id %}" class="title" style="background-color: {{ item.get_color_display }}">{{ item.name }}</a>
                    {# 项目盒子底部 #}
                    <div class="info">
                        <div>
                            {# 项目星标 #}
                            <a href="{% url 'project_star' project_type='my' project_id=item.id %}">
                                <i class="fa fa-star" aria-hidden="true" style="color: #d5d5d5"></i>
                            </a>
                            {# 项目创建者 #}
                            <span>{{ item.creator.username }}</span>
                        </div>
                        <div>
                            {# 参与人数 #}
                            <i class="fa fa-user-o" aria-hidden="true"></i>
                            <span>{{ item.join_count }}</span>
                        </div>
                    </div>

                </div>
            {% endfor %}
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading"><i class="fa fa-handshake-o" aria-hidden="true"></i> 我参与的项目</div>
        <div class="panel-body">
            {#显示项目#}
            {% for item in project_dict.join %}
                {# 项目盒子 #}
                <div class="item">
                    {#项目盒子 颜色展示 项目名称显示#}
                    <a href="{% url 'dashboard' project_id=item.id %}" class="title" style="background-color: {{ item.get_color_display }}">{{ item.name }}</a>
                    {# 项目盒子底部 #}
                    <div class="info">
                        <div>
                            {# 项目星标 #}
                            <a href="{% url 'project_star' project_type='join' project_id=item.id %}">
                                <i class="fa fa-star" aria-hidden="true" style="color: #d5d5d5"></i>
                            </a>
                            {# 项目创建者 #}
                            <span>{{ item.creator.username }}</span>
                        </div>
                        <div>
                            {# 参与人数 #}
                            <i class="fa fa-user-o" aria-hidden="true"></i>
                            <span>{{ item.join_count }}</span>
                        </div>
                    </div>

                </div>
            {% endfor %}
        </div>
    </div>

{% endblock %}

{% block js %}
    <script>
        $(function () {
            bindSubmit();

        })
        function bindSubmit() {
            $('#btnSubmit').click(function () {
                //清空上次输入报错
                $('.error-msg').empty();
                $.ajax({
                    uri: "{% url 'project_list' %}",
                    type: "POST",
                    data: $('#addForm').serialize(),
                    dataType: "JSON",
                    success: function (res) {
                        console.log(res);
                        if (res.status) {
                            location.href = location.href;
                        } else {
                            $.each(res.error, function (key, value) {
                                $("#id_" + key).next().text(value[0])
                            })
                        }
                    }
                })
            })
        }
    </script>
{% endblock %}
